home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-06-26 | 1.8 KB | 114 lines | [TEXT/MMCC] |
- #include "SortPicts.h"
-
-
- void SortPicts::MakeThreaded( void)
- {
- ThreadID tempThreadInfo;
- OSErr errWhatErr;
-
- randomSeed = TickCount();
-
- unitCount = newUnitCount = 1;
-
- startTime = TickCount();
-
- errWhatErr = NewThread( kCooperativeThread,
- SortPictsThreadEntry,
- (void *)this,
- 100000,
- kCreateIfNeeded,
- (void**)nil,
- &tempThreadInfo);
-
- if( errWhatErr)
- DebugStr( "\pXcuzzU? NewThread Failed??");
-
- threadInfo = tempThreadInfo;
-
- YieldToThread( threadInfo);
-
- }
-
-
- pascal void *SortPictsThreadEntry( void *there)
- {
- SortPicts *t = (SortPicts *)there;
-
- t->Entry();
-
- return nil;
- }
-
-
- void SortPicts::Entry( void)
- {
- while( 1)
- {
- Scramble();
- Update();
- Sort();
- }
- }
-
-
- /*
- * SetSortItem
- *
- */
- void SortPicts::SetSortItem( long index, long data)
- {
- long horiz, vert;
- long offset;
-
- horiz = index % pictWidth;
- vert = index / pictWidth;
-
- if( vert >= copyBitsRect.bottom)
- copyBitsRect.bottom = vert+1;
-
- if( vert < copyBitsRect.top)
- copyBitsRect.top = vert;
-
- sortData[index] = data;
- offset = horiz + (vert * pictRowBytes);
- sortPixels[offset] = (SortPixel) data;
-
- if( !unitCount--)
- Yield();
- }
-
- void SortPicts::ExchangeSortItem( long one, long theOther)
- {
- long temp;
-
- temp = sortData[one];
- SetSortItem( one, sortData[theOther]);
- SetSortItem( theOther, temp);
- }
-
-
- void SortPicts::Yield( void)
- {
- CalculateNewUnitCount();
- Update();
- UnuseSortData();
- YieldToAnyThread();
- startTime = TickCount();
- UseSortData();
- }
-
- void SortPicts::CalculateNewUnitCount( void)
- {
- long deltaTime = TickCount() - startTime;
-
- if( deltaTime)
- newUnitCount = (int) (((_Float) newUnitCount) *
- // ((_Float) kYieldTime / (_Float) deltaTime));
- ((_Float) 6 / (_Float) deltaTime));
- else
- newUnitCount = newUnitCount * 6 + 1;
-
- unitCount = newUnitCount;
- }
-
-